package com.bsoft.controller;

import com.bsoft.mapper.UserMapper;
import com.bsoft.pojo.UserDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EchcacheController {

    private static final String CACHE_NAME_USER = "users";
    @Autowired
    private UserMapper userMapper;
    @Autowired(required = false)
    private CacheManager cacheManager;

    @GetMapping("/testCacheManager")
    public void testCacheManager() {
        System.out.println(cacheManager);
    }

    @GetMapping("/test")
    public void testSelectById() {
        Integer id = 1;
        //查询id=1的记录
        UserDo userDo = userMapper.selectById(id);
        System.out.println("user" + userDo);
        //判断缓存中是否有
        //System.out.println("缓存为空"+cacheManager.getCache(CACHE_NAME_USER).get(userDo.getId(),UserDo.class));
        System.out.println("开始从缓存中查询=======>");
        //查询id =1的记录
        UserDo userDo1 = userMapper.selectById(id);
        System.out.println("user======>" + userDo1);

    }
}
